let appType
appType = "MP-WEIXIN"

let env = judgeEnv()
// 生产: 'product' 预上线: 'release' 测试: 'test' 开发: 'dev'
env = 'test'

export default {
	env, // 环境类型 生产: 'product' 预上线: 'release' 测试: 'test' 开发: 'dev'
	host: buildHost(), // 请求的API，基础路径
	salt: buildSalt(), // 请求签名加盐
  imgUrlPath: buildImgUrl()
}
/**
 * 判断环境类型生成env
 */
function judgeEnv() {
	//#ifdef H5
	let href = location.href;
	if(href.indexOf('https://mgmall.migudm.cn/release')>=0 || href.indexOf('http://mgmall.migudm.cn/release')>=0 ){
		return 'release';
	}else if(href.indexOf('https://mgmall.migudm.cn')>=0 || href.indexOf('http://mgmall.migudm.cn')>=0){
		return 'product';
	}else if(href.indexOf('http://112.48.155.25:18080/mgmall_test')>=0){
		return 'test';
	}else if(href.indexOf('http://112.48.155.25:18080/mgmall_hotfix')>=0){
		return 'hotfix';
	}else{
		return 'dev';
	}
	//#endif
	//#ifdef MP-WEIXIN
	const opts = wx.getLaunchOptionsSync()
	if (opts.query && opts.query.__env) {
		return opts.query.__env;
	} else {
		return 'product'
	}
	//#endif
}
/**
 * 生成请求基础路径
 */
function buildHost() {
	let apiHost_pro = appType == "H5" ? "" : "https://www.talentmatch.top"
	let apiHost_test = appType == "H5" ? "" : "https://www.talentmatch.top"
    const hostList = {
		"product": `${apiHost_pro}`,
		"release": `${apiHost_pro}`,
		"hotfix": `${apiHost_test}`,
		"test": `${apiHost_test}`,
		"dev": `${apiHost_test}`
	}
	return hostList[env]
}
/**
 * 请求加盐
 */
function buildSalt() {
	const saltList = {
		"product": `5y7e4ea5agY3a70afGaxc96631jf7dfe1Uca1V391`,
		"release": `5y7e4ea5agY3a70afGaxc96631jf7dfe1Uca1V391`,
		"hotfix": `hell`,
		"test": `hell`,
		"dev": `hell`,
	}
	return saltList[env]
}

/**
 * 生成图片显示地址
 * @returns {string}
 */
function buildImgUrl() {
  if (['test', 'dev'].includes(env)) {
    return 'http://112.48.155.28:28080/static_test/'
  } else {
    return 'https://ss.migudm.cn/'
  }
}
